package com.ciei.dpagm.common.enums;

import com.baomidou.mybatisplus.annotation.EnumValue;

import java.util.Arrays;

/**
 * 权限缓存
 *
 * @author kiho
 * @date 2022/11/17
 */
public enum RightNoCacheEnum {

    /**
     * 会被<keep-alive>缓存（默认）
     */
    CACHE(0, false),

    /**
     * 不会被 <keep-alive> 缓存
     */
    NO_CACHE(1, true),
    ;

    @EnumValue
    private Integer value;

    private boolean isNoCache;

    RightNoCacheEnum(Integer value, boolean isNoCache) {
        this.value = value;
        this.isNoCache = isNoCache;
    }

    public Integer getValue() {
        return value;
    }

    public boolean isNoCache() {
        return isNoCache;
    }

    public static boolean getBooleanByValue(Integer value) {
        return Arrays.stream(values())
                .filter(noCacheEnum -> noCacheEnum.getValue().equals(value))
                .map(RightNoCacheEnum::isNoCache)
                .findFirst()
                .orElse(false);
    }
}
